@extends('admin.pop_edit')
@section('body')
    <form class="layui-form" style="padding: 20px;" lay-verType="tips" lay-filter="form"
          action="{{admin_url($baseRoute.'permission')}}">
        <input type="hidden" name="id" value="{{$id}}"/>
        <input type="hidden" name="actions[]" value="0"/>
        <table class="layui-table">
            <colgroup>
                <col width="180">
                <col width="50">
                <col>
            </colgroup>
            <thead>
            <tr>
                <th>@lang('system.permission.module')</th>
                <th>@lang('system.permission.all')</th>
                <th>@lang('system.permission.permission')</th>
            </tr>
            </thead>

            <tbody>
            @foreach($permissions as $permission)
                <tr>
                    <td>
                        {!! $permission['title_show'] !!}
                    </td>
                    @if(isset($permission['actions']))
                        <td>
                            <input type="checkbox" name="" lay-skin="primary" class="checkAll" lay-filter="checkAll">
                        </td>
                    @else
                        <td></td>
                    @endif
                    <td>
                        @if(isset($permission['actions']))
                            @foreach($permission['actions'] as $action=>$name)
                                <input type="checkbox" name="actions[]"
                                       title="{{$name['name']}}" lay-skin="primary" class="checkItem"
                                       value="{{$permission['controller'].'@'.$action}}"
                                       @if($name['checked']) checked @endif>
                            @endforeach
                        @endif
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        <div class="layui-form-item">
            <button class="layui-btn" lay-submit lay-filter="ajaxForm">@lang('system.permission.save')</button>
        </div>
    </form>
@stop
@push('script')
    <script>
        layui.use('form', function () {
            var $ = layui.jquery, form = layui.form;
            //全选
            form.on('checkbox(checkAll)', function (data) {
                var child = $(data.elem).parents('tr').find('td input[type="checkbox"]');
                child.each(function (index, item) {
                    item.checked = data.elem.checked;
                });
                form.render();
            });
        });
    </script>
@endpush